Skip to content

Add PrecompileTools to reduce TTFX by up to 8000x#27

Merged
ChrisRackauckas merged 1 commit into
SciML:mainfrom
ChrisRackauckas-Claude:precompile-improvements-20251230-001519
Dec 30, 2025
Merged

Add PrecompileTools to reduce TTFX by up to 8000x#27
ChrisRackauckas merged 1 commit into
SciML:mainfrom
ChrisRackauckas-Claude:precompile-improvements-20251230-001519

Conversation

@ChrisRackauckas-Claude

Copy link
Copy Markdown
Contributor

Summary

  • Added PrecompileTools.jl dependency with a precompilation workload
  • Precompiles common FunctionWrappersWrapper creation and call patterns with Float64/Int types
  • Dramatically reduces time-to-first-execution (TTFX) for typical use cases

Benchmark Results

Metric Before After Improvement
using FunctionWrappersWrappers ~0.175s ~0.195s +11% (PrecompileTools loading overhead)
TTFX: FunctionWrappersWrapper creation ~0.088s ~0.0002s 518x faster
TTFX: First call (Float64) ~0.58s ~0.00007s 8286x faster
TTFX: Second type call (Int) ~0.053s ~0.00007s 757x faster

The startup time has a small overhead from loading PrecompileTools, but the TTFX improvements are dramatic - all compilation now happens during package precompilation instead of at runtime.

Analysis

  • No invalidations detected when loading the package
  • Precompilation time: ~2.9s (acceptable tradeoff for the TTFX improvements)
  • All existing tests pass

Test plan

  • Measured baseline startup time and TTFX
  • Added PrecompileTools workload for common use patterns
  • Verified TTFX improvements after precompilation
  • All existing tests pass (Pkg.test())

cc @ChrisRackauckas

🤖 Generated with Claude Code

@ChrisRackauckas-Claude ChrisRackauckas-Claude force-pushed the precompile-improvements-20251230-001519 branch from f270233 to 5041885 Compare December 30, 2025 05:22
Added a PrecompileTools workload to precompile common use patterns,
dramatically improving time-to-first-execution (TTFX):

- FunctionWrappersWrapper creation: ~0.088s -> ~0.0002s (518x faster)
- First call dispatch (Float64): ~0.58s -> ~0.00007s (8286x faster)
- Second type call dispatch (Int): ~0.053s -> ~0.00007s (757x faster)

The precompilation workload covers:
- Binary operations with Float64 and Int argument types
- Unary operations with Float64 and Int argument types
- Both creation and call dispatch for each

No invalidations were detected when loading the package.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@ChrisRackauckas-Claude ChrisRackauckas-Claude force-pushed the precompile-improvements-20251230-001519 branch from 5041885 to 786d0f3 Compare December 30, 2025 05:24
@ChrisRackauckas-Claude

Copy link
Copy Markdown
Contributor Author

Rebased on latest main to include the new introspection functions (unwrap, wrapped_signatures, wrapped_return_types).

Updated precompilation workload also includes these new functions. Note that unwrap has a small remaining compilation time (~6ms) due to the internal Ref dereference, but this is minor compared to the major TTFX improvements for the core functionality.

Final benchmark results (runs 2-3 after precompilation):

Function Time
using FunctionWrappersWrappers ~0.18s
FunctionWrappersWrapper creation ~0.0002s
First call (Float64) ~0.00007s
Second type call (Int) ~0.00007s
unwrap ~0.006s (residual compilation)
wrapped_signatures ~0.00003s
wrapped_return_types ~0.00003s

All tests pass.

@ChrisRackauckas ChrisRackauckas merged commit 8b0b14a into SciML:main Dec 30, 2025
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants